<?php
namespace ZHMVC\B\TOOL;
class Clsfun
{
    private $_classid;
    private $data1String;
    private $data2String;
    
    function __construct($classid="")
    {
        $this->data1String="";
        $this->data2String="";
        $this->_classid=$classid;
    }
    
    // 递归显示分类
    function data1arr($tree, $rootId = 0, $level = 0)
    {
        foreach ($tree as $leaf) {
            if ($leaf['fid'] == $rootId) {
                $this->data1String.="<tr>
                        <td>|" . str_repeat('----', $level) . "&nbsp;&nbsp;&nbsp;(" . $leaf['id'] . ")</td>
                        <td>" . $leaf['name'] . "</td>
                        <td>";
                if($leaf['fid']==0)
                {
                    $this->data1String.="根栏目";
                }
                else
                {
                    $where="id='".$leaf['fid']."'";
                    $rs1=new \ZHMVC\D\Frontmenu();
                    $data1=$rs1->getOne1($where);
                    $this->data1String.=$data1['name'];
                    $rs1=null;
                }
                $this->data1String.="</td>
                        <td>";
                if ($leaf['ismenu'] == "1") {
                    $this->data1String.="显示";
                } else {
                    $this->data1String.="隐藏";
                }
                $this->data1String.="</td>
                       <td>" . $leaf['ordernum'] . "</td>
                        <td>" . $leaf['phpfile'] . "</td>
                       <td><a href=\"?atcion=add&classid=".$this->_classid."&postid=" . $leaf['id'] . "\">修改</a>&nbsp;&nbsp;&nbsp;";

                    $this->data1String.="&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href=\"?atcion=del&classid=".$this->_classid."&postid=" . $leaf['id'] . "\">删除</a>";
                $this->data1String.="</td>
                      </tr>";
                foreach ($tree as $l) {
                    if ($l['fid'] == $leaf['id']) {
                        self::data1arr($tree, $leaf['id'], $level + 1);
                        break;
                    }
                }
            }
        }
    }
    
    // 递归显示分类
    function data1option($tree, $rootId = 0, $level = 0, $ckfid = 0)
    {
        foreach ($tree as $leaf) {
            if ($leaf['fid'] == $rootId) {
                if ($ckfid == $leaf['id']) {
                    $this->data2String.="<option value='" . $leaf['id'] . "' selected>" . str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level) . $leaf['name'] . "</option>";
                } else {
                    $this->data2String.="<option value='" . $leaf['id'] . "'>" . str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level) . $leaf['name'] . "</option>";
                }
                foreach ($tree as $l) {
                    if ($l['fid'] == $leaf['id']) {
                        self::data1option($tree, $leaf['id'], $level + 1, $ckfid);
                        break;
                    }
                }
            }
        }
    }
    
    
    function getData1()
    {
        return $this->data1String;
    }
    
    function getData2()
    {
        return $this->data2String;
    }
    
    
    function __destruct()
    {
        $this->data1String="";
    }
}